package com.qiaquan.server;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import java.util.logging.Logger;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timer;

public class Server {
	public static Logger logger = Logger.getLogger("server logger");

	private final int port;

	public Server(int port) {
		this.port = port;
	}

	Timer timer = new HashedWheelTimer();

	public void run() {
		// Configure the server.
		ServerBootstrap bootstrap = new ServerBootstrap(
				new NioServerSocketChannelFactory(
						Executors.newCachedThreadPool(),
						Executors.newCachedThreadPool()));

		// Set up the pipeline factory.
		bootstrap.setPipelineFactory(new ServerPipelineFactory(timer));

		// Bind and start to accept incoming connections.
		bootstrap.bind(new InetSocketAddress(port));
		
		
	}

	public static void main(String[] args) throws Exception {
		int port = 20134;
		new Server(port).run();
		logger.info("server startup success!!!");
	}
}
